package edu;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPserver {
    public static void main(String[] args) throws IOException {
        String host = "127.0.0.1";
        int port = 5000;
        try (ServerSocket serverSocket = new ServerSocket(port)){
            System.out.println("服务器已启动，等待客户连接");
            Socket socket = serverSocket.accept();
            System.out.println("客户端已连接"+socket.getInetAddress().getHostAddress());

            BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String clientMessage = in.readLine();
            System.out.println("收到客户消息"+clientMessage);
            PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
            out.println("我收到了你的消息"+clientMessage);

            socket.close();
            System.out.println("连接已关闭");

        }

    }
}
